package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dk.model.RelaterProductBom;
import com.dk.mapper.RelaterProductBomMapper;
import com.dk.service.RelaterProductBomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.vo.RelaterProductBomVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wbh
 * @since 2023-03-20
 */
@Service
public class RelaterProductBomServiceImpl extends ServiceImpl<RelaterProductBomMapper, RelaterProductBom> implements RelaterProductBomService {
    @Resource
    private RelaterProductBomMapper relaterProductBomMapper;

    @Override
    public List<RelaterProductBomVO> getBomListById(Integer id) {
        LambdaQueryWrapper<RelaterProductBom> wrapper = new LambdaQueryWrapper();
        wrapper.eq(RelaterProductBom::getRelatedProductId, id);
        List<RelaterProductBomVO> collect = relaterProductBomMapper.selectList(wrapper).stream().map(relaterProductBom -> {
            RelaterProductBomVO vo = new RelaterProductBomVO();
            BeanUtils.copyProperties(relaterProductBom, vo);
            return vo;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public void insertInfoRelaterProductBom(RelaterProductBomVO relaterProductBomVO) {
        RelaterProductBom relaterProductBom = new RelaterProductBom();
        BeanUtils.copyProperties(relaterProductBomVO,relaterProductBom);
        relaterProductBomMapper.insert(relaterProductBom);
    }

    @Override
    public RelaterProductBomVO getInfoRelaterProductBomById(Integer id) {
        RelaterProductBom relaterProductBom = relaterProductBomMapper.selectById(id);
        RelaterProductBomVO vo = new RelaterProductBomVO();
        BeanUtils.copyProperties(relaterProductBom,vo);
        return vo;
    }

    @Override
    public void updateInfoRelaterProductBomById(RelaterProductBomVO relaterProductBomVO) {
        RelaterProductBom relaterProductBom = new RelaterProductBom();
        BeanUtils.copyProperties(relaterProductBomVO,relaterProductBom);
        relaterProductBomMapper.updateById(relaterProductBom);
    }

    @Override
    public void deleteInfoRelaterProductBomById(Integer id) {
        relaterProductBomMapper.deleteById(id);
    }

    @Override
    public void deleteInfoRelaterProductByRelatedId(Integer id) {
        LambdaQueryWrapper<RelaterProductBom> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RelaterProductBom::getRelatedProductId,id);
        relaterProductBomMapper.delete(wrapper);
    }

    @Override
    public void deleteInfoRelaterProductBomByIds(List<Integer> list) {
        relaterProductBomMapper.deleteBatchIds(list);
    }
}
